import java.awt.image.BufferedImage;

public class ExtraPlane extends ArmyPlane implements Shoot{
    //属性
    private int movei;
    private int reBoold;
    //构造器


    public ExtraPlane(int x){
        super(165,261,x+165>StaticNumber.WINWID?x-165:x,-261,StaticNumber.EXTSPEED,StaticNumber.EXTBOOLD,StaticNumber.EXT_SCORE,StaticNumber.EXT_ATTACK_SPEED);

        //进入停止线后，判断离哪边远，往远的方向随机移动一段距离(至少30)
        movei = getX()>StaticNumber.WINWID-getWidth()-getX()?-(int)(Math.random()*(getX()-30))+30:(int)(Math.random()*(StaticNumber.WINWID-getWidth()-getX()-30))+30;

        reBoold = getBoold();
//        System.out.println("创建了一个Boss敌机");
    }

    //方法
    @Override
    void Move() {
        if (getY()<100&&PlayPanel.getTime()%getSpeed()==0){
            setY(getY()+1);
        }
        if (getY()>=100&&PlayPanel.getTime()%getSpeed()==0){
            if (movei>0){
                setX(getX()+1);
                movei--;
            }else if (movei<0){
                setX(getX()-1);
                movei++;
            }else{
                movei = getX()>StaticNumber.WINWID-getWidth()-getX()?-(int)(Math.random()*(getX()-30))+30:(int)(Math.random()*(StaticNumber.WINWID-getWidth()-getX()-30))+30;
            }
        }

    }
    private int i = 2;
    @Override
    BufferedImage getImage() {

        if (reBoold == getBoold()){
            return Game.extimg[PlayPanel.getTime()/300%2];
        }else{
            if (PlayPanel.getTime()%100==0||reBoold<getBoold()-1){
                reBoold = getBoold();
            }
            return Game.extimg[2];
        }
    }


    @Override
    public void creatBullet() {
        if (PlayPanel.getTime()%getCreatebulletspeed() == 0&&getY()>=100){
            PlayPanel.getArmybullets().add(new LaserBullet(getX()+30,getY()+getHight()-10,getAttack(),true));
            PlayPanel.getArmybullets().add(new LaserBullet(getX()+getWidth()-30,getY()+getHight()-10,getAttack(),true));
        }
    }
}
